<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>任务管理 - 威客任务平台</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
        <div class="container">
            <a class="navbar-brand" href="/">威客任务平台</a>
            <div class="navbar-nav ms-auto">
                <a class="nav-link" th:href="@{/dashboard}">仪表板</a>
                <a class="nav-link" th:href="@{/admin/users}">用户管理</a>
                <a class="nav-link" th:href="@{/admin/tasks}">任务管理</a>
                <a class="nav-link" th:href="@{/logout}">退出</a>
            </div>
        </div>
    </nav>

    <div class="container mt-4">
        <div class="d-flex justify-content-between align-items-center mb-4">
            <h2>任务管理</h2>
        </div>
        
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>任务标题</th>
                    <th>雇主</th>
                    <th>预算</th>
                    <th>状态</th>
                    <th>发布时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <tr th:each="task : ${tasks}">
                    <td th:text="${task.taskId}"></td>
                    <td th:text="${task.title}"></td>
                    <td th:text="${task.employerId}"></td>
                    <td th:text="${'¥' + #numbers.formatDecimal(task.budget, 1, 2)}"></td>
                    <td>
                        <span th:if="${task.taskStatus == 'open'}" class="badge bg-primary">待承接</span>
                        <span th:if="${task.taskStatus == 'in_progress'}" class="badge bg-warning">进行中</span>
                        <span th:if="${task.taskStatus == 'completed'}" class="badge bg-success">已完成</span>
                        <span th:if="${task.taskStatus == 'closed'}" class="badge bg-secondary">已关闭</span>
                    </td>
                    <td th:text="${#temporals.format(task.publishDate, 'yyyy-MM-dd HH:mm')}"></td>
                    <td>
                        <a th:href="@{/admin/tasks/{id}(id=${task.taskId})}" class="btn btn-sm btn-primary">查看</a>
                        <a th:href="@{/admin/tasks/edit/{id}(id=${task.taskId})}" class="btn btn-sm btn-warning">编辑</a>
                        <a th:href="@{/admin/tasks/delete/{id}(id=${task.taskId})}" 
                           class="btn btn-sm btn-danger"
                           onclick="return confirm('确定要删除这个任务吗？')">删除</a>
                    </td>
                </tr>
            </tbody>
        </table>
        
        <div th:if="${tasks == null or tasks.empty}" class="alert alert-info">
            暂无任务
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>